package com.qf.student.response;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

/**
 * @author YaoJiXing
 * created 2022/11/21 14:38
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@Accessors(chain = true)
public class R<T> {

    private int code;
    private String msg;
    private T data;


    private R(String msg) {
        this.msg = msg;
    }

    private R(T data) {
        this.data = data;
    }

    private R(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    private R(int code, T data) {
        this.code = code;
        this.data = data;
    }

    private R(String msg, T data) {
        this.msg = msg;
        this.data = data;
    }

    public static R createSuccess() {
        return new R(RCodes.SUCC.getCode(), RCodes.SUCC.getMsg());
    }

    public static R createSuccess(String msg) {
        return new R(RCodes.SUCC.getCode(), msg);
    }

    public static <T> R createSuccess(T data) {
        return new R(RCodes.SUCC.getCode(), data);
    }

    public static <T> R createSuccess(int code, String msg) {
        return new R(code, msg);
    }

    public static <T> R createSuccess(int code, T data) {
        return new R(code, RCodes.SUCC.getMsg(), data);
    }

    public static <T> R createSuccess(String msg, T data) {
        return new R(RCodes.SUCC.getCode(), msg, data);
    }


    
    public static R createFAIL() {
        return new R(RCodes.FAIL.getCode(), RCodes.FAIL.getMsg());
    }

    public static R createFAIL(String msg) {
        return new R(RCodes.FAIL.getCode(), msg);
    }

    public static <T> R createFAIL(T data) {
        return new R(RCodes.FAIL.getCode(), data);
    }

    public static <T> R createFAIL(int code, String msg) {
        return new R(code, msg);
    }

    public static <T> R createFAIL(int code, T data) {
        return new R(code, RCodes.FAIL.getMsg(), data);
    }

    public static <T> R createFAIL(String msg, T data) {
        return new R(RCodes.FAIL.getCode(), msg, data);
    }

    /**
     * 全部数据的返回对象
     * @param code
     * @param msg
     * @param data
     * @return
     * @param <T>
     */
    public static <T> R createR(int code, String msg, T data) {
        return new R(code, msg, data);
    }

}
